package com.shop.admin.controller;

import com.shop.Result.LdbzResult;
import com.shop.admin.service.AdminItemService;
import com.shop.pojo.LdbzItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/item/service")
public class AdminItemController {

    private static final Logger logger = LoggerFactory.getLogger(AdminItemController.class);

    @Autowired
    private AdminItemService adminItemService;

    @RequestMapping(value="/editItem/{id}" , method = RequestMethod.GET)
    public LdbzResult editItem(@PathVariable("id")long id , Model model) {
        return adminItemService.selectByKey(id);
    }

    @RequestMapping(value="/getItemList" , method = RequestMethod.GET)
    public LdbzResult getItemList(LdbzItem entity) {
        return adminItemService.getItemList(entity);
    }

    @RequestMapping(value="/getItemPage" , method = RequestMethod.GET)
    public LdbzResult getItemPage(LdbzItem entity , int page , int limit) {
        return adminItemService.getItemPage(entity, page, limit);
    }

    @RequestMapping(value="/deleteByKey/{id}" , method = RequestMethod.GET)
    public LdbzResult deleteByKey(@PathVariable("id")String id) {
        return adminItemService.deleteByKey(id);
    }

    @RequestMapping(value="/insertByEntity" , method = RequestMethod.GET)
    public LdbzResult insertByEntity(LdbzItem entity) {
        return adminItemService.insertByEntity(entity);
    }

    @RequestMapping(value="/updateByKey" , method = RequestMethod.GET)
    public LdbzResult updateByKey(LdbzItem entity) {
        return adminItemService.updateByEntity(entity);
    }

    @RequestMapping(value="/syncItemToSolrByCode/{code}" , method = RequestMethod.GET)
    public LdbzResult syncItemToSolrByCode(@PathVariable("code")long code) {
        return adminItemService.syncItemToESByCode(code);
    }
}
